Edit in GitHubLog an issue

Page caching

Caching is one of the most effective ways to improve website performance. Generally speaking, there are two methods of caching content:

  • Client-side (browser)
  • Server-side

Retrieving stored (cached) content from a previous request for the same client instead of requesting files from your server every time someone visits your site is a more efficient use of network bandwidth.

The Adobe Commerce and Magento Open Source page cache library contains a simple PHP reverse proxy that enables full page caching out of the box. A reverse proxy acts as an intermediary between visitors and your application and can reduce the load on your server.

We recommend using Varnish, but you can use the default caching mechanism instead, which stores cache files in any of the following:

  • File system (You don't need to do anything to use file-based caching.)
  • Database
  • Redis

Cacheable and uncacheable pages

Cacheable and uncacheable are terms we use to indicate whether or not a page should be cached at all. (By default, all pages are cacheable except the checkout pages.) If any block in a layout is designated as uncacheable, the entire page is uncacheable.

To create an uncacheable page, mark any block on that page as uncacheable in the layout using cacheable="false".

Copied to your clipboard
<block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Magento_Customer::form/edit.phtml" cacheable="false">
<container name="form.additional.info" as="form_additional_info"/>
</block>

Examples of uncacheable pages include the compare products, cart, checkout pages, and so on.

Example

Public and private content

Reverse proxies serve "public" or shared content to more than one user. However, most Adobe Commerce and Magento Open Source websites generate dynamic and personalized "private" content that should only be served to one user, which presents unique caching challenges. To address these challenges, the application can distinguish between two types of content:

  • Public - Public content is stored server side in your reverse proxy cache storage (e.g., file system, database, Redis, or Varnish) and is available to multiple customers. Examples of public content include header, footer, and category listing.

  • Private - Private content is stored client side (e.g., browser) and is specific to an individual customer. Examples of private content include wishlist, shopping cart, customer name, and address. You should limit stored private content to a small portion of the page's total content.

Cache types

The following cache types mostly have impact on frontend development process:

Cache type "friendly" nameCache type code nameDescription
Layout
layout
Compiled page layouts (that is, the layout components from all components). Clean or flush this cache type after modifying layout files.
Block HTML output
block_html
HTML page fragments per block. Clean or flush this cache type after modifying the view layer.
Page cache
full_page
Generated HTML pages. If necessary, the application cleans up this cache automatically, but third-party developers can put any data in any segment of the cache. Clean or flush this cache type after modifying code level that affects HTML output. It's recommended to keep this cache enabled because caching HTML improves performance significantly.
Translations
translate
Merged translations from all modules.

Clean cache

To clean cache, run

Copied to your clipboard
bin/magento cache:clean <type> <type>

To view the status of the cache, run:

Copied to your clipboard
bin/magento cache:status

For more details about working with cache, see Manage the cache

Clean static files cache

You can clean generated static view files in any of the following ways:

  • In the Admin. Go to System > Tools > Cache Management and click Flush Static Files Cache.

    {:.bs-callout-info} This option is only available in developer mode. Refer to the static view files overview for more information. For more details about the application modes, see application modes

  • Manually by clearing the pub/static and var/view_preprocessed directories and subdirectories except for pub/static/.htaccess.

    To clear the pub/static directory of all files except .htaccess (which is a hidden file), enter the following command:

    Copied to your clipboard
    rm -r pub/static/*/*

    To clear the var/view_preprocessed, enter the following command:

    Copied to your clipboard
    rm -r var/view_preprocessed/*
  • Several commands support an optional parameter --clear-static-content, which cleans generated static view files:

Clean static files

Besides the cached files, in theme development process developers also deal with other saved files - static view files that are preprocessed and published to the var/view_preprocessed and pub/static directories correspondingly. In most cases when working on a custom theme, for example, if you are only working on styles, you do not need to clean cache, but need to clean the previously preprocessed and published static view files. To clean them, run grunt clean <theme> or manually clear the pub/static and var/view_preprocessed directories.

  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.